package employee;

import java.time.LocalDate;
import java.util.Date;

/**
 * 铁饭碗员工类
 * 继承自员工类的子类：拿固定工资的员工
 * 新增属性：基础工资，岗位工资
 */
public class SalariedEmployee extends Employee {
    /**
    * 基础工资
    */
    private int basicSalary;
    /**
     * 岗位工资
     */
    private int positionSalaty;

    /**
     * 父类
     * @param id 员工编号
     * @param name 姓名
     * @param dateBirth 出生日期
     * @param dateOnboarding 入职年月
     * 自己
     * @param basicSalary 基础工资
     * @param positionSalaty 岗位工资
     */
    public SalariedEmployee(int id, String name, Date dateBirth, Date dateOnboarding, int basicSalary, int positionSalaty) {
        super(id, name, dateBirth, dateOnboarding, basicSalary + positionSalaty);
        this.basicSalary = basicSalary;
        this.positionSalaty = positionSalaty;
    }

    /**
     * 支持链式编程的计算工资的方法
     * 根据参数年份和月份来计算某年某月工资，该员工入职时间每多满1年则每月增加2元的工龄工资;
     * 如果该月员工过生日，则公司会额外奖励200元。
     *
     * @param year  年份
     * @param month 月份
     * @return 该类本身
     */
    @Override
    public Employee setSalary(int year, int month) {
        return super.setSalary(year, month);
    }

    public int getPositionSalaty() {
        return positionSalaty;
    }

    public int getBasicSalary() {
        return basicSalary;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SalariedEmployee)) return false;
        if (!super.equals(o)) return false;

        SalariedEmployee that = (SalariedEmployee) o;

        if (getBasicSalary() != that.getBasicSalary()) return false;
        return getPositionSalaty() == that.getPositionSalaty();

    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + getBasicSalary();
        result = 31 * result + getPositionSalaty();
        return result;
    }

    @Override
    public String toString() {
        return "SalariedEmployee{" +
                "basicSalary=" + basicSalary +
                ", positionSalaty=" + positionSalaty +
                ", id=" + getId() +
                ", name=" + getName() + '\'' +
                ", dateBirth=" + getDateBirth() +
                ", dateOnboarding=" + getDateOnboarding() +
                ", wages=" + getWages() +
                ", totalSalary=" + getTotalSalary() +
                '}';
    }
}
